package com.zpark.rabbitmq.route;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.zpark.rabbitmq.config.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @PackageName: com.zpark.rabbitmq.route
 * @ClassName: Product
 * @Description:
 * @author: RZS
 * @date: 2022/12/13  17:08
 */
public class Product {
    // 定义交换机名字
    private static final String EXCHANGE_NAME = "test_exchange_direct";

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection conn = ConnectionUtil.getConnection();
        Channel channel = conn.createChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, "direct");
        for (int i=0; i<100; i++) {
            String msg = "Hello, World! " + i;
            channel.basicPublish(EXCHANGE_NAME, "delete", null, msg.getBytes());
            System.out.println("生产者，发送消息 msg -> " + msg);
        }
        channel.close();
        conn.close();
    }
}
